<template>
  <div>
    <div>
      <el-divider content-position="left">1.维修回访设置</el-divider>
      <FormPanel ref="form" :list="formList" labelWidth="200" :cols="2" :isSubmitBtn="false" @formChange="formChangeHandle" />
    </div>
    <div>
      <el-divider content-position="left">2.销售回访设置</el-divider>
      <FormPanel ref="form1" :list="formList1" labelWidth="200" :cols="2" :isSubmitBtn="false" @formChange="formChangeHandle1" />
    </div>
    <div>
      <el-divider content-position="left">3.二手车回访设置</el-divider>
      <FormPanel ref="form2" :list="formList2" labelWidth="200" :cols="2" :isSubmitBtn="false" @formChange="formChangeHandle2" />
    </div>
    <div>
      <el-divider content-position="left">4.活动回访设置</el-divider>
      <FormPanel ref="form3" :list="formList3" labelWidth="200" :cols="2" :isSubmitBtn="false" @formChange="formChangeHandle3" />
    </div>
    <div>
      <el-divider content-position="left">5.回访任务分配设置</el-divider>
      <FormPanel ref="form4" :list="formList4" labelWidth="200" :cols="2" :isSubmitBtn="false" @formChange="formChangeHandle4" />
    </div>
    <div style="text-align:center">
      <el-button  type="primary" @click="saveHandler" >保存</el-button >
    </div>
  </div>
</template>

<script>
import dictCode from '@/utils/dictCode';
import { dictionary } from '@/utils/dictMixin';
import { queryAllParam,updateBasicParam } from '@/api/customerRepair/visitRules/visitRulesSet';
export default {
  name: 'Rules',
  mixins: [dictionary],
  data() {
    this.saveData = null;
    this.saveData1 = null;
    this.saveData2 = null;
    this.saveData3 = null;
    this.saveData4 = null;
    return {
      formList: this.createFormList(),
      formList1: this.createFormList1(),
      formList2: this.createFormList2(),
      formList3: this.createFormList3(),
      formList4: this.createFormList4()
    };
  },
   mounted() {
    this.queryDefaultPa();
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'CHECKBOX',
          label: '部分结算委托单是否进入回访任务',
          fieldName: '1001',
          change: val => {},
          options: {
            trueValue: '10041001',
            falseValue: '10041002'
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '结算后第',
          fieldName: '1002',
          initialValue: 0,
          style: { width: '100px' },
          descOptions: {
            content: '天进行回访'
          }
        },
        {
          type: 'MULTIPLE_CHECKBOX',
          label: '参与回访委托单类别',
          fieldName: '1003',
          itemList: [
            { text: '0-首保', value: '1001' },
            { text: '1-维修', value: '1002' },
            { text: '2-保养', value: '1003' },
            { text: '3-小修', value: '1004' },
            { text: '4-大修', value: '1005' },
            { text: '5-事故', value: '1006' },
            { text: '6-返工', value: '1007' },
            { text: '7-年审', value: '1008' },
            { text: '8-PDI', value:  '1009' },
            { text: '9-内修', value: '1010' },
            { text: 'A-保险', value: '1011' },
            { text: 'G-索赔优惠', value: '1012' },
            { text: 'M-免费检测', value: '1013' },
            { text: 'P-预PDI', value: '1014' },
            { text: 'S-市场服务', value: '1015' },
            { text: 'U-外出救援', value: '1016' },
            // { text: 'V-行动', value: '1017' },
            { text: 'Z-召回', value: '1018' }
          ],
          selfCols: 1.5
        }
      ];
    },
    createFormList1() {
      return [
        {
          type: 'MULTIPLE_CHECKBOX',
          label: '计划回访任务日期设置',
          fieldName: '2001',
          itemList: [
            { text: '成交日期', value: '1001' },
            { text: '提车日期', value: '1002' }
          ]
        },
        {
          type: 'INPUT_NUMBER',
          label: '成交/提车后第',
          fieldName: '2002',
          style: { width: '100px' },
          descOptions: {
            content: '天进行回访'
          }
        }
      ];
    },
    createFormList2() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '成交后第',
          fieldName: '3001',
          style: { width: '100px' },
          descOptions: {
            content: '天进行回访'
          }
        },
        {
          type: 'MULTIPLE_CHECKBOX',
          label: '哪些业务参与回访',
          fieldName: '3002',
          itemList: [
            { text: '零售', value: '1001' },
            { text: '收购', value: '1002' },
            { text: '寄售', value: '1003' }
          ]
        }
      ];
    },
    createFormList3() {
      return [
        {
          type: 'INPUT_NUMBER',
          label: '活动完成后第',
          fieldName: '4001',
          style: { width: '100px' },
          descOptions: {
            content: '天进行回访'
          }
        }
      ];
    },
    createFormList4() {
      return [
        {
          type: 'CHECKBOX',
          label: '人工分配回访任务',
          fieldName: '5001',
          change: val => {},
          options: {
            trueValue: '10041001',
            falseValue: '10041002'
          }
        },
        {
          type: 'CHECKBOX',
          label: '已回访数据是否参与分配',
          fieldName: '5002',
          change: val => {},
          options: {
            trueValue: '10041001',
            falseValue: '10041002'
          }
        }
      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    formChangeHandle1(val) {
      this.saveData1 = val;
    },
    formChangeHandle2(val) {
      this.saveData2 = val;
    },
    formChangeHandle3(val) {
      this.saveData3 = val;
    },
    formChangeHandle4(val) {
      this.saveData4 = val;
    },
    async saveHandler() {
      this.$refs.form.SUBMIT_FORM();
      this.$refs.form1.SUBMIT_FORM();
      this.$refs.form2.SUBMIT_FORM();
      this.$refs.form3.SUBMIT_FORM();
      this.$refs.form4.SUBMIT_FORM();
      let obj = Object.assign(
        {},
        this.saveData,
        this.saveData1,
        this.saveData2,
        this.saveData3,
        this.saveData4
      );
      let res = await updateBasicParam(obj);
      if (res.resultCode === 200) {
        this.test();
        this.closeDialog();
      }
    },
     closeDialog(param) {
      this.$refs.form.RESET_FORM();
      this.$refs.form1.RESET_FORM();
      this.$refs.form2.RESET_FORM();
      this.$refs.form3.RESET_FORM();
      this.$refs.form4.RESET_FORM();
      this.queryDefaultPa();
    },
    test() {
      this.$notify({
        title: '成功',
        message: '成功',
        type: 'success'
      });
    },

     async queryDefaultPa() {
       let res = await queryAllParam();
       this.formList.find(x => x.fieldName === '1001').initialValue = res.data['1001'];
       this.formList.find(x => x.fieldName === '1002').initialValue = res.data['1002'];
       this.formList.find(x => x.fieldName === '1003').initialValue = res.data['1003'];
       console.log(res.data['1003'].length,'zzzzzzz')
       this.formList1.find(x => x.fieldName === '2001').initialValue = res.data['2001'];
       this.formList1.find(x => x.fieldName === '2002').initialValue = res.data['2002'];
       this.formList2.find(x => x.fieldName === '3001').initialValue = res.data['3001'];
       this.formList2.find(x => x.fieldName === '3002').initialValue = res.data['3002'];

      this.formList3.find(x => x.fieldName === '4001').initialValue = res.data['4001'];
      this.formList4.find(x => x.fieldName === '5001').initialValue = res.data['5001'];
      this.formList4.find(x => x.fieldName === '5002').initialValue = res.data['5002'];
     }
  }
};
</script>

<style scoped></style>
